/**
 *Project: coreHardy
 *File: cn.xkshow.io.upload.SimpleUpload.java 
 *Author: admin@xkshow.cn with the copyrite
 ****************************************************************
 *   VERSION       DATE            BY       CHANGE/COMMENT
 * --------------------------------------------------------------
 *    1.0        2013-4-26        xkshow.cn         create
 ****************************************************************
 *note:
 ***************************************************************/ 
package cn.xkshow.io.upload;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class SimpleUpload {
	private static final int BUFFER_SIZE = 16 * 1024;
	
	public SimpleUpload(){
		
	}
	/*
	 * 自己封装的一个把源文件对象复制成目标文件对象
	 */
	public static void copy(File src, String dstPath) {
        InputStream in = null;
        OutputStream out = null;
        File dst = null;
        try {
        	dst = new File(dstPath);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

        try {
            in = new BufferedInputStream(new FileInputStream(src), BUFFER_SIZE);
            out = new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);
            
            byte[] buffer = new byte[BUFFER_SIZE];
            int len = 0;
            
            while ((len = in.read(buffer)) > 0) {
                out.write(buffer, 0, len);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != in) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (null != out) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}
